<?php

namespace app\enterprise\model\staff;

use app\model\TimeModel;

class Staff extends TimeModel
{
    protected $table = 'sj_staff';

    public static function getPage($where, $page = 1, $limit = 10)
    {
        $list = (new self)->where('status', '>', '0')->where($where)
            ->order('id desc, create_time desc')
            ->paginate($limit)
            ;
        return $list;
    }

    public static function getList($where)
    {
        $list = (new self)->where('status', '>', '0')->where($where)
            ->order(['create_time' => 'desc'])
            ->select()->toArray();
        return $list;
    }

    public static function getAlllist(): array
    {
        return (new self)->where('status', '>', '0')
            ->order(['pid' => 'asc','sort' => 'asc', 'create_time' => 'desc'])
            ->select()->toArray();
    }
    /**
     * 新增记录
     */
    public function add($data)
    {
        return self::create($data);
    }
    

    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return self::update($data, ['id' => $data['id'], 'company_id' => $data['company_id']]);
    }

    /**
     * 软删除
     */
    public function setDelete($where)
    {
        return self::update(['statust' => -1], $where);
    }

    public function getById($id, $company_id)
    {
        return self::where('id' , $id)->where('company_id', '=' , $company_id)->where('status' , '>', 0)->find();
    }
}